package src.accenture.com.backing;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import src.accenture.com.Common.CommonUtil;
import src.accenture.com.entity.MblEmployee;
import src.accenture.com.session.SessionEJB;

public class Login {
    private String _username;
    private String _password;
    private String _message;
    
    private Context context = null;
    private SessionEJB sessionBean;

    public void setUsername(String _username) {
        this._username = _username.toLowerCase();
    }

    public String getUsername() {
        return _username;
    }

    public void setPassword(String _password) {
        this._password = _password;
    }

    public String getPassword() {
        return _password;
    }
    
    public void setMessage(String _message) {
        this._message = _message;
    }

    public String getMessage() {
        return _message;
    }
    
    public Login() throws NamingException {
        context = new InitialContext();
        sessionBean = (SessionEJB)context.lookup("HolidaySessionEJB#src.accenture.com.session.SessionEJB");        
    }
    
    public String doLogin() { 
       
        MblEmployee empLogin = sessionBean.getEmployeeLogin(this._username, this._password);
                
        if (null != empLogin) {
            
            CommonUtil.setMblEmployeeToSession(empLogin);
            return "login";    
        } else {
            this.setMessage("Login failed!");
            return null;
        }     
    }    
}
